{extend name="public:layout" /}
{block name="title"}推荐位管理{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 推荐位管理</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left form-inline">
                    <select class="form-control" onchange="javascript:location.href=this.value;">
                        {volist name="moudle" id="vo"}
                        <option value="{:url('index',['mid'=>$vo['mid']])}" {eq name="vo.mid" value="$Request.param.mid"}selected{/eq}>
                        {$vo.moudle_name}
                        </option>
                        {/volist}
                    </select>
                    <a class="btn btn-primary" href="javascript:;" onclick="editSave();">
                        <i class="fa fa-edit"></i>&nbsp;批量修改
                    </a>
                </div>
                <div class="pull-right">
                    <input type="text" name="flagName" style="width:180px;" class="form-control pull-left"/>
                    <a class="btn btn-info pull-left" href="javascript:;" onclick="add();">
                        <i class="fa fa-plus"></i>&nbsp;添加推荐位
                    </a>
                </div>
                <div class="clearfix"></div>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>推荐位</th>
                    <th width="80">删除</th>
                </tr>
                </thead>
                <tbody>
                {volist name="flagList" id="vo"}
                <tr>
                    <td>{$i}</td>
                    <td>
                        <input type="text" class="form-control flagName" style="width:220px;" name="flag[]" value="{$vo}"/>
                    </td>
                    <td>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('del')}"
                           data-params="mid={$Request.param.mid}&index={$i-1}">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    //批量添加
    function add() {
        var flagName = $("input[name='flagName']").val();
        var url = "{:url('add',['mid'=>$Request.param.mid])}";
        getAjax(url, {flagName:flagName}, function (data) {
            if (data.code == 1) {
                rePage();
            }else{
                layer.alert(data.msg);
            }
        });
    }
    //批量保存
    function editSave() {
        var params = $(".flagName").serialize();
        var url = "{:url('edit',['mid'=>$Request.param.mid])}";
        getAjax(url, params, function (data) {
            if (data.code == 1) {
                rePage();
            }else{
                layer.alert(data.msg);
            }
        });
    }
</script>
{/block}